package vn.edu.hut.soict.translate.wordgraph;

import java.util.List;

public class SimpleWord implements Word {
	private String text;
	private List<String> partOfSpeechs;

	public SimpleWord(String text, List<String> partOfSpeechs) {
		this.text = text;
		this.partOfSpeechs = partOfSpeechs;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public List<String> getPartOfSpeechs() {
		return partOfSpeechs;
	}

	public void setPartOfSpeechs(List<String> partOfSpeechs) {
		this.partOfSpeechs = partOfSpeechs;
	}

	@Override
	public String partOfSpeech() {
		return partOfSpeechs.toString();
	}

	public boolean isContentWord() {
		if (partOfSpeechs != null) {
			for (String pos : partOfSpeechs) {
				char type = pos.charAt(0);
				if (type == 'A' || type == 'N' || type == 'P' || type == 'V' || type == 'I') {
					return true;
				}
			}
		}
		return false;
	}

	public boolean samePartOfSpeech(Word w) {
		if (!(w instanceof SimpleWord)) {
			return false;
		}
		SimpleWord word = (SimpleWord) w;
		if (partOfSpeechs != null && word.partOfSpeechs != null) {
			for (String pos1 : partOfSpeechs) {
				for (String pos2 : word.partOfSpeechs) {
					if (pos1.equals(pos2)) {
						return true;
					}
				}
			}
		}
		return false;
	}

	public boolean isIdentical(Word w) {
		if (w == null) {
			return false;
		}
		if (!(w instanceof SimpleWord)) {
			return false;
		}
		SimpleWord word = (SimpleWord) w;
		if (!text.equals(word.text)) {
			return false;
		}
		if (partOfSpeechs.size() != word.partOfSpeechs.size()) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		SimpleWord other = (SimpleWord) obj;
		if (!text.equals(other.text)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return text;
	}
}